package top.pengdong.pictureShare.tweet.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.pengdong.pictureShare.common.model.SysConstant;
import top.pengdong.pictureShare.tweet.dao.PsCommentDao;
import top.pengdong.pictureShare.tweet.dao.PsCountDao;
import top.pengdong.pictureShare.tweet.dao.PsTweetDao;
import top.pengdong.pictureShare.tweet.entity.PsCommentEntity;
import top.pengdong.pictureShare.tweet.entity.PsCount;
import top.pengdong.pictureShare.tweet.entity.PsTweetEntity;
import top.pengdong.pictureShare.tweet.service.PsCountService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("psCountService")
public class PsCountServiceImpl extends ServiceImpl<PsCountDao, PsCount> implements PsCountService {

	@Resource
	private PsCountDao psCountDao;

	@Resource
	private PsTweetDao psTweetDao;

	@Resource
	private PsCommentDao psCommentDao;

	@Override
	public Integer getUserCount() {
		return psCountDao.getUserCount();
	}

	/**
	 * redis 记录优化值 TODO
	 * @return
	 */
	@Override
	public Object getUserMap() {
		// 获取评论分布
		List<Object> dataList = new ArrayList<>();
		for (String str : SysConstant.MAP_PROVINCE) {
			Map<String, Object> map = new HashMap<>();
			List list = new ArrayList();
			map.put("name", str);
			// 获取文章地区信息
			Long ipAddress = psTweetDao.selectCount(new QueryWrapper<PsTweetEntity>()
					.like("ip_address", str));
			Map<String, Object> map1 = new HashMap<>();
			map1.put("name", "文章属地");
			map1.put("value", ipAddress);
			list.add(map1);
			// 获取评论属地
			Long ipAddress1 = psCommentDao.selectCount(new QueryWrapper<PsCommentEntity>()
					.like("ip_address", str));
			Map<String, Object> map2 = new HashMap<>();
			map2.put("name", "评论属地");
			map2.put("value", ipAddress1);
			list.add(map2);

			map.put("value", list);
			dataList.add(map);
		}
		return dataList;
	}
}
